import 'dart:math';

import 'package:flutter/material.dart';
import 'package:wsc2022/TabBar/TabView1.dart';
import 'package:wsc2022/TabBar/TabView2.dart';
import 'package:wsc2022/TabBar/TabView3.dart';
import 'package:wsc2022/newsDetail_page.dart';
import 'package:wsc2022/resultDetail_page.dart';

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> with SingleTickerProviderStateMixin{

  late TabController _tabController;


  @override
  void initState() {
    _tabController = TabController(
      initialIndex: 0,
      length: 3,
      vsync: this,
    );
    super.initState();
  }




  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: NestedScrollView(
        floatHeaderSlivers: true,
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              // backgroundColor: Colors.transparent,
              flexibleSpace: Container(
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage('images/bgc1.png'),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              expandedHeight: 300,
              toolbarHeight: 100,
              // centerTitle: true,
              pinned: true,
              // floating: true,
              bottom: TabBar(
                  indicatorColor: Colors.white,
                  labelPadding: const EdgeInsets.only(
                    bottom: 16,
                  ),
                  controller: _tabController,
                  tabs: [
                    Text("News"),
                    Text("Results"),
                    Text("History"),
                  ]),
            ),
          ];
        },
        body: TabBarView(
          controller: _tabController,
          children: [
            TabView1(),
            TabView2(),
            TabView3()
          ],
        ),
      ),
    );
  }
  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }
}



class TabA extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scrollbar(
      child: ListView.separated(
        separatorBuilder: (context, child) => Divider(
          height: 1,
        ),
        padding: EdgeInsets.all(0.0),
        itemCount: 30,
        itemBuilder: (context, i) {
          return Container(
            height: 100,
            width: double.infinity,
            color: Colors.primaries[Random().nextInt(Colors.primaries.length)],
          );
        },
      ),
    );
  }
}


